using UnityEngine;
using System.Collections.Generic;

namespace UndergroundSurvival.Rooms
{
    public class LivingRoom : BaseRoom
    {
        [Header("Living Room Settings")]
        [SerializeField] private int maxOccupants = 4;
        [SerializeField] private float mentalRecoveryRate = 0.1f;
        [SerializeField] private float sleepRecoveryRate = 0.2f;

        private List<GameObject> occupants = new List<GameObject>();

        protected override void Update()
        {
            base.Update();

            if (!isBuilt || !isFunctioning) return;

            // 处理居住者的状态恢复
            foreach (var occupant in occupants)
            {
                if (occupant != null)
                {
                    // 恢复精神状态
                    if (PlayerStatsManager.Instance != null)
                    {
                        PlayerStatsManager.Instance.ModifyMental(mentalRecoveryRate * Time.deltaTime);
                        PlayerStatsManager.Instance.ModifySleep(sleepRecoveryRate * Time.deltaTime);
                    }
                }
            }
        }

        public bool AddOccupant(GameObject occupant)
        {
            if (occupants.Count >= maxOccupants)
                return false;

            occupants.Add(occupant);
            return true;
        }

        public void RemoveOccupant(GameObject occupant)
        {
            occupants.Remove(occupant);
        }

        public override void OnRoomUpgraded()
        {
            base.OnRoomUpgraded();
            maxOccupants += 2;
        }

        public int GetCurrentOccupants()
        {
            return occupants.Count;
        }

        public int GetMaxOccupants()
        {
            return maxOccupants;
        }

        public bool HasSpace()
        {
            return occupants.Count < maxOccupants;
        }
    }
} 